Skip to content

fix(gpu): stop copy_mapped on non-writable title destinations instead of faulting - #3358

Open
reeledMarek wants to merge 1 commit into
Marvisak:mainfrom
reeledMarek:fix/gpu-copy-mapped-readonly-dst
Open

reeledMarek wants to merge 1 commit into
Marvisak:mainfrom
reeledMarek:fix/gpu-copy-mapped-readonly-dst

Conversation

@reeledMarek

Copy link
Copy Markdown
Contributor

Summary

  • When copy_mapped(dst, src, len, title_dst = true) fails its initial ReadProcessMemory call because the destination contains committed PAGE_READONLY (or execute-only) pages, crate::texture::committed(dst, len) previously returned true (since committed only rejects PAGE_NOACCESS | PAGE_GUARD for readable sources).
  • The fallback loop then failed read() on each 4 KiB piece and executed unsafe { to.write_bytes(0, n) }, causing an immediate access violation on the read-only title destination.
  • Adds a writable(dst, len) check (requiring MEM_COMMIT, no PAGE_NOACCESS | PAGE_GUARD, and a writable base protection) before entering the fallback for title_dst, and routes title_dst zero-fills through read(ZERO_4K.as_ptr(), to, n) so concurrent protection changes cannot fault either.
  • Adds regression test title_copies::title_copies_do_not_fault_on_read_only_destinations using VirtualProtect(..., PAGE_READONLY).

Verification

  • cargo clippy -p victory-gpu --all-targets --target x86_64-pc-windows-msvc --locked -- -D warnings
  • cargo test -p xtask --locked

@Dukestar69 Dukestar69 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — verified on Windows against origin/main (63bcca4).

  • Checking writable(dst, len) (instead of only committed) and using read(ZERO_4K.as_ptr(), to, n) on title_dst prevents copy_mapped from faulting on read-only title destination pages during the fallback path.
  • cargo test -p victory-gpu --lib host::title_copies:: -- --test-threads=1: 3 passed, 0 failed (including title_copies_do_not_fault_on_read_only_destinations).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants